package cn.utils;


import java.util.List;

@SuppressWarnings("unchecked")
public class PageModel {

	//放对象的list
	private List list;
	//当前页
	private int currentPage=1;
	//总页数
	private int totalPage;
	//总记录条数
	private int totalCount;
	//每页的记录数量
	private int pageSize=10;

	public PageModel(){
	}

	//-- 构造函数 初始pageSize --//
	public PageModel(int pageSize){
		this.pageSize=pageSize;
	}

	public List getList() {
		return list;
	}

	public void setList(List list) {
		this.list = list;
	}

	//设置当前页的页号,序号从1开始,低于1时自动调整为1.
	public int getCurrentPage() {
		return currentPage<1?1:currentPage;
	}

	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage<1?1:currentPage;
	}

	public int getTotalPage() {
		if (totalCount < 0) {
			return -1;
		}

		int count = totalCount / pageSize;
		if (totalCount % pageSize > 0) {
			count++;
		}
		return count;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public int getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(int totalCount) {
		this.totalCount = totalCount;
	}

	public int getPageSize() {
		return pageSize;
	}

	//设置每页的记录数量,低于1时自动调整为1
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize<1?(pageSize==0?10:1):pageSize;
	}

	//根据pageNo和pageSize计算当前页第一条记录在总结果集中的位置,序号从1开始.
	public int getFirst(){
		return currentPage * pageSize-pageSize + 1;
	}

	public int getBeginIndex(){
		return ((currentPage-1)*pageSize);
	}
}
